
import { Provide, Inject } from '@midwayjs/core';
import { GroupDao } from '@dao/group.dao';
import { CreateGroupDto, UpdateGroupDto, QueryGroupDto, QueryGroupStudentDto } from '@dto/group.dto';
import { DownloadExcelService } from '../service/common/downloadExcel';
@Provide()
export class GroupService {
  @Inject()
  groupDao: GroupDao;
  @Inject()
  downloadExcelService: DownloadExcelService;
   // 创建
  async create(body: CreateGroupDto) {
    return await this.groupDao.create(body);
  }
  // 获取列表
  async list(query: QueryGroupDto) {
    return await this.groupDao.list(query);
  }

  // 根据年级ID获取分组列表
  async listByGrade(gradeId: number) {
    return await this.groupDao.listByGrade(gradeId);
  }
  // 根据年级ID和教师ID获取分组列表
  async listByGradeAndTeacher(gradeId: number, teacherId: number) {
    return await this.groupDao.listByGradeAndTeacher(gradeId, teacherId);
  }
  // 获取详情
  async detail(groupId: string) {
    return await this.groupDao.detail(+groupId);
  }
  // 修改
  async update( body: UpdateGroupDto) {
    return await this.groupDao.update(body);
  }
  // 删除
  async remove(groupIds: Array<number>) {
    return await this.groupDao.remove(groupIds);
  }
  // 导出
  async export(queryParams: QueryGroupDto) {  
    const headers = [
      { label: '分组ID', prop: 'groupId' },
      { label: '分组专业ID', prop: 'majorIds' },
      { label: '分组教师ID', prop: 'teacherIds' },
      { label: '分组名称', prop: 'groupName' },
      { label: '队伍最大人数', prop: 'teamMax' },
      { label: '教师最大人数', prop: 'teacherMax' },
      { label: '开始时间', prop: 'startTime' },
      { label: '结束时间', prop: 'endTime' },
      { label: '备注', prop: 'remark' },
      { label: '状态（0正常 1停用）', prop: 'status' }
    ];
    const { rows } = (await this.groupDao.list(queryParams)).data;
    return this.downloadExcelService.downloadExcel({
      headers,
      data: rows,
      sheetName: 'Group信息',
    });
  }
   async detailStudent(groupId: number, query: QueryGroupStudentDto) {
    return await this.groupDao.detailStudent(groupId, query);
  }

  async detailTeacher(groupId: number) {
    return await this.groupDao.detailTeacher(groupId);
  }
}